/**
 * 
 */
package design_pattern.interpreter;

/**
 * @author linzq
 * 
 */
public class OR implements Expression {

  private Expression left, right;

  public OR(Expression left, Expression right) {
    this.left = left;
    this.right = right;
  }

  @Override
  public boolean interpret(Context ctx) {
    return left.interpret(ctx) && right.interpret(ctx);
  }

  @Override
  public int hashCode() {
    return this.toString().hashCode();
  }

  /**
   * 检验两个表达式在结构上是否相同
   */
  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof OR) {
      return this.left.equals(((OR) obj).left) && this.right.equals(((OR) obj).right);
    }
    return false;
  }

  @Override
  public String toString() {
    return "(" + left.toString() + " OR " + right.toString() + ")";
  }

}
